package com.share.web.action.oa.org;

import javax.annotation.Resource;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.share.bean.oa.org.EmpCard;
import com.share.commons.util.WebSiteUrl;
import com.share.service.oa.org.EmpCardManager;
import com.share.web.action.base.BaseActionSupport;

@Controller
@Scope("prototype")
public class EmpCardAction extends BaseActionSupport {

	private static final long serialVersionUID = 1L;

	private EmpCard empCard;
	
	private String empNocardId ;


	public String getEmpNocardId() {
		return empNocardId;
	}

	public void setEmpNocardId(String empNocardId) {
		this.empNocardId = empNocardId;
	}

	@Resource
	private EmpCardManager empCardMgr;

	public String addEmpCard() throws Exception {
		try {
		this.empCardMgr.saveEmpCardManager(empCard, empNocardId) ;

		}catch (Exception e) {
			e.printStackTrace() ;
		}
		
		return "pub_add_success";
	}
	
	public String updateEmpCard() throws Exception {
		empCard.setId(Integer.parseInt(empNocardId.split(",")[1])) ;
		this.empCardMgr.updateEmpCardManager(empCard) ;

		return "pub_add_success";
	}

	public String loadEmpCard() throws Exception {
		EmpCard ec = this.empCardMgr.loadEmpCardManager(empNocardId) ;
		this.getBaseform().getRequest().setAttribute("empCard", ec) ;
		
		if(null != ec) {
			this.getBaseform().getRequest().setAttribute("goPath", WebSiteUrl.readUrl("web.employee.updateEmpCard")) ;
		} else {
			this.getBaseform().getRequest().setAttribute("goPath", WebSiteUrl.readUrl("web.employee.saveEmpCard")) ;
		}
		return "loadEmpCard";
	}

	public EmpCard getEmpCard() {
		return empCard;
	}

	public void setEmpCard(EmpCard empCard) {
		this.empCard = empCard;
	}

	public void setEmpCardMgr(EmpCardManager empCardMgr) {
		this.empCardMgr = empCardMgr;
	}

}
